nesting the condtions Service#disable_agents within :where_not

Dominik Sander 10 年之前
父节点
当前提交
770af574bd
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      app/models/service.rb

+ 2 - 2
app/models/service.rb

@@ -16,7 +16,7 @@ class Service < ActiveRecord::Base
16 16
   scope :by_name, lambda { |dir = 'desc'| order("services.name #{dir}") }
17 17
 
18 18
   def disable_agents(conditions = {})
19
-    agents.where.not(conditions).each do |agent|
19
+    agents.where.not(conditions[:where_not] || {}).each do |agent|
20 20
       agent.service_id = nil
21 21
       agent.disabled = true
22 22
       agent.save!(validate: false)
@@ -24,7 +24,7 @@ class Service < ActiveRecord::Base
24 24
   end
25 25
 
26 26
   def toggle_availability!
27
-    disable_agents(user_id: self.user_id) if global
27
+    disable_agents(where_not: {user_id: self.user_id}) if global
28 28
     self.global = !self.global
29 29
     self.save!
30 30
   end